/*
DESCRIPTION
This do file creates the figures in the main text.

INPUT
	data/BITTrialAdoption.dta
	data/Forecasts.dta
	data/Survey.dta
	data/policyadoption_raw.csv // Hjort et al. (2021) data from http://doi.org/10.3886/E122661V1 

OUTPUT
	figures/te_control_newpre.pdf
	figures/adoption.pdf.pdf
	figures/adoption_by_tebin.pdf
	figures/adoption_by_tebin10.pdf
	figures/adoption_by_tbin.pdf
	figures/which_arm_adopted.pdf
	figures/adoption_by_citypop.pdf
	figures/adoption_by_WWC.pdf
	figures/adoption_by_staff.pdf
	figures/adoption_by_mech.pdf
	figures/adoption_by_preexist.pdf
	figures/adoption_by_med_preexist.pdf
	figures/adoption_by_any_preexist.pdf
	figures/adoption_by_sig_preexist.pdf
	figures/adoption_by_tebin5_preexist.pdf
	figures/survey.pdf
	figures/counterfactuals.pdf
	figures/hjort_fig.txt
*/

******************************************
***FIGURE 2: TRIAL ADOPTION AND EFFECTS***
******************************************
{
	clear all
	use "data/BITTrialAdoption.dta"

	*Coordinates for labeled outliers
	qui sum controltakeup if trialnumber==2016059
	local A_c = r(mean)+2
	qui sum treatmenteffect_max if trialnumber==2016059
	local A_te = r(mean)
	local A_x = `A_c'+5
	local A_y = `A_te'

	qui sum controltakeup if trialnumber==2017171
	local B_c = r(mean)-2
	local B_x = `B_c'-5
	qui sum treatmenteffect_max if trialnumber==2017171
	local B_te = r(mean)
	local B_y = `B_te'
	local B_ytxt = `B_y'+1

	qui sum controltakeup if trialnumber==2015105
	local C_c = r(mean)+2
	qui sum treatmenteffect_max if trialnumber==2015105
	local C_te = r(mean)
	local C_x = `C_c'+5
	local C_y = `C_te'

	qui sum controltakeup if trialnumber==2018132
	local D_c = r(mean)+2
	qui sum treatmenteffect_max if trialnumber==2018132
	local D_te = r(mean)
	local D_x = `D_c'+5
	local D_y = `D_te'

	qui sum controltakeup if trialnumber==2017001
	local E_c = r(mean)+2
	qui sum treatmenteffect_max if trialnumber==2017001
	local E_te = r(mean)
	local E_x = `E_c'+5
	local E_y = `E_te'

	qui sum treatmenteffect_max
	local ate=`r(mean)'
	local atestr=string(`ate',"%4.2f")

	qui count if treatmenteffect_max!=.
	local tr=`r(N)'

	twoway rcap treatmenteffect_LB treatmenteffect_UB controltakeup, lstyle(ci) || ///
			scatter treatmenteffect_max controltakeup if adopted==99, mcolor(maroon%30) msym(square) || ///
			scatter treatmenteffect_max controltakeup if adopted==99, mcolor(green%60) msym(square) || ///
			scatter treatmenteffect_max controltakeup if adopted==99, mlcolor(black) mfcolor(white%0) msym(circle) || ///
			scatter treatmenteffect_max controltakeup if adopted==99, mlcolor(black) mfcolor(white%0) msym(D) || ///
		   scatter treatmenteffect_max controltakeup if adopted==0 & comm_preexisted==0, mcolor(maroon%30) msym(circle) || ///
		   scatter treatmenteffect_max controltakeup if adopted==0 & comm_preexisted==1, mcolor(maroon%30) msym(D) || ///
		   scatter treatmenteffect_max controltakeup if adopted==1 & comm_preexisted==0, mcolor(green%60) msym(circle) || ///
		   scatter treatmenteffect_max controltakeup if adopted==1 & comm_preexisted==1, mcolor(green%60) msym(D) || ///
		   pcarrowi 	`A_y' `A_x' `A_te' `A_c' (3) "Letters enforcing delinquent sewer bill payment" ///
						`B_y' `B_x' `B_te' `B_c' ///
						`C_y' `C_x' `C_te' `C_c' (3) "Courtesy reminders for sewer bill payment" ///
						`D_y' `D_x' `D_te' `D_c' (3) "Redesigned webpage encouraging applications to city board" ///
						`E_y' `E_x' `E_te' `E_c' (3) "Newsletter emphasizing fresh start for bike-share" ///
				7 90 `ate' 90 (12) `" "Avg. max TE=`atestr'pp." "' ///
		   , ///
		   mcolor(navy) lcolor(navy) mlabcolor(navy) mlabsize(small) ///
		   text(`B_ytxt' `B_c' "Emails prompting" "online AutoPay" "registration for" "city bills", place(nw) color(navy) size(small) just(center)) ///
		   yline(`ate', lcolor(gray%50) lw(medthick) lpattern(dash)) ///
		   xscale(range(0 100)) ///
		   yscale(range(-20 40)) ///
		   yline(0, lcolor(gray)) ///	   
		   xlabel(0(20)100) xmtick(0(20)100) ylabel(-20(10)40) ymtick(-20(10)40) ///
		   graphregion(color(white)) bgcolor(white) ///
		   ytitle("Max treatment effect in trial arms (pp.)") xtitle("Control take-up (%)") ///
		   note("BIT-NA sample: `tr' trials") ///
		   legend(order(2 "Not adopted" 3 "Adopted" 4 "New" 5 "Pre-existing"))
	graph export "figures/te_control_newpre.pdf", replace
}

**************************************
***FIGURE 3: BASELINE ADOPTION RATE***
**************************************
{
	clear all
	use "data/BITTrialAdoption.dta"
	keep if sample==1
	append using "data/Forecasts.dta"
	replace cityid=_n+1000 if cityid==.
		
	gen byte benchmark1=treatmenteffect_max>0 if sample==1
	gen byte benchmark2=treatmenteffect_maxt>=invnorm(0.975) if sample==1

	mat bar=J(4,7,.) 
	mat colnames bar = bin p_adopt lb ub N N_adopt N_nadopt

	local r=1
	forvalues t=1/2 {
		qui reg benchmark`t', cl(cityid)
		mat bar[`r',1]=`t'
		mat bar[`r',2]=_b[_cons]
		mat bar[`r',3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
		mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
		qui count if benchmark`t'!=.
		mat bar[`r',5]=r(N)
		qui count if benchmark`t'==1
		mat bar[`r',6]=r(N)
		qui count if benchmark`t'==0
		mat bar[`r',7]=r(N)
		local ++r
	}

	qui reg adopt_baseline, r
	eststo y
	mat bar[3,1]=3
	mat bar[3,2]=_b[_cons]
	mat bar[3,3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
	mat bar[3,4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
	qui count if adopt_baseline!=.
	mat bar[3,5]=r(N)
	qui count if adopt_baseline!=.
	mat bar[3,6]=r(N)
	qui count if adopt_baseline!=.
	mat bar[3,7]=r(N)
	
	qui reg adopted, cl(cityid)
	local true=_b[_cons]
	mat bar[4,1]=4
	mat bar[4,2]=_b[_cons]
	mat bar[4,3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
	mat bar[4,4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
	qui count if adopted!=.
	mat bar[4,5]=r(N)
	qui count if adopted==1
	mat bar[4,6]=r(N)
	qui count if adopted==0
	mat bar[4,7]=r(N)
	
	*pvals
	qui reg benchmark1
	est sto b1
	qui reg benchmark2
	est sto b2
	qui reg adopt_baseline
	est sto b3
	qui reg adopted
	est sto y
	
	suest b3 y, cl(cityid)
	lincom [b3_mean]_cons - 100*[y_mean]_cons
	local pvalA=string(`r(p)',"%3.2f")
	
	suest b2 y, cl(cityid)
	lincom [b2_mean]_cons - [y_mean]_cons
	local pvalB=string(`r(p)',"%3.2f")
	
	suest b1 y, cl(cityid)
	lincom [b1_mean]_cons - [y_mean]_cons
	local pvalC=string(`r(p)',"%3.2f")

	clear
	svmat bar, names(col)
	
	replace p_adopt=p_adopt*100 if bin!=3
	
	tostring p_adopt, gen(barlabel) format("%2.0f") force
	replace barlabel=barlabel+"%"
	
	tostring N, replace format("%3.0f") force
	tostring N_adopt, replace format("%3.0f") force
	
	replace barlabel=barlabel+" ("+N_adopt+"/"+N+")" if bin!=3
	replace barlabel=barlabel+" (N="+N_adopt+")" if bin==3
		
	egen max=max(p_adopt), by(bin)
	replace max=max+1
	
	sort bin
	gen 	x=_n*0.3
	qui sum x
	local mx=`r(max)'+0.15
	
	local group1 3
	local group2 4
	qui sum max if bin==`group1'
	local y1startA=`r(max)'+2
	qui sum max if bin==`group2'
	local y2startA=`r(max)'+2
	local ystartA=max(`y1startA',`y1startA')
	local yendA=`ystartA'+3
	qui sum x if bin==`group1'
	local x1A=`r(mean)'
	qui sum x if bin==`group2'
	local x2A=`r(mean)'
	local xcentA=(`x1A'+`x2A')/2
	
	local group1 2
	local group2 4
	qui sum max if bin==`group1'
	local y1startB=`r(max)'+2
	qui sum max if bin==`group2'
	local y2startB=`r(max)'+2
	local ystartB=max(`y1startB',`y1startB')
	local yendB=`ystartB'+3
	qui sum x if bin==`group1'
	local x1B=`r(mean)'
	qui sum x if bin==`group2'
	local x2B=`r(mean)'
	local xcentB=(`x1B'+`x2B')/2
	
	local group1 1
	local group2 4
	qui sum max if bin==`group1'
	local y1startC=`r(max)'+2
	qui sum max if bin==`group2'
	local y2startC=`r(max)'+2
	local ystartC=max(`y1startC',`y1startC')
	local yendC=`ystartC'+3
	qui sum x if bin==`group1'
	local x1C=`r(mean)'
	qui sum x if bin==`group2'
	local x2C=`r(mean)'
	local xcentC=(`x1C'+`x2C')/2
	
	gen byte zero=0
		
	twoway 	(bar p_adopt x if bin==1, barwidth(0.2) lcolor(dkgreen) fcolor(dkgreen%50)) ///
			(bar p_adopt x if bin==2, barwidth(0.2) lcolor(dkgreen) fcolor(dkgreen%50)) ///
			(bar p_adopt x if bin==3, barwidth(0.2) lcolor(gray) fcolor(gray%50)) ///
			(bar p_adopt x if bin==4, barwidth(0.2) lcolor(ebblue) fcolor(ebblue%50)) ///
			(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
			(pci 	`ystartA' `x1A' `yendA' `x1A'   `ystartA' `x2A' `yendA' `x2A'   `yendA' `x1A' `yendA' `x2A' ///
					`ystartB' `x1B' `yendB' `x1B'   `ystartB' `x2B' `yendB' `x2B'   `yendB' `x1B' `yendB' `x2B' ///
					`ystartC' `x1C' `yendC' `x1C'   `ystartC' `x2C' `yendC' `x2C'   `yendC' `x1C' `yendC' `x2C' ///
					, lcolor(gray%50)) ///
			, ///
			graphregion(color(white)) bgcolor(white) ///
			xscale(range(0.15 `mx')) yscale(range(0 100)) yticks(0(10)100) ylabel(0(10)100) ///
			xlabel(0.3 `" " " "Effect size{&gt}0pp." "' 0.45 "{bf:Adopt if max:}" 0.6 `" " " "{it:t}-stat{&ge}1.96" "' 0.9 "Forecasted mean" 1.2 "Adopted", noticks) ///
			legend(off) ///
			xtitle(" ") ytitle("Percent of trials") ///
			text(`yendA' `xcentA' "{it:p}=`pvalA'", size(small) placement(n)) ///
			text(`yendB' `xcentB' "{it:p}=`pvalB'", size(small) placement(n)) ///
			text(`yendC' `xcentC' "{it:p}=`pvalC'", size(small) placement(n)) ///
			xline(0.75, lpattern(dash) lcolor(gray%50)) ///
			xline(1.05, lpattern(dash) lcolor(gray%50)) ///
			text(100 0.45 "{bf:Counterfactual adoption rules}", placement(6)) ///
			text(100 1.2 "{bf:Observed}" "{bf:adoption rate}", placement(6)) ///
			text(100 0.9 "{bf:Forecasted}" "{bf:adoption rate}", placement(6)) ///
			xsize(8) ysize(6)
	graph export "figures/adoption.pdf", replace
}

*****************************************
***FIGURE 5: ADOPTION BY EFFECTIVENESS***
*****************************************
{
	{ // 5a and 5b
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1
		append using "data/Forecasts.dta"
		replace cityid=_n+1000 if missing(cityid)
		
		* Binscatter of adoption by 10 treatment effect bins
		local ylab
		forvalues l=0(0.1)0.7 {
			local ll=`l'*100
			local ylab `ylab' `l' "`ll'"
		}

		binscatter2 adopted treatmenteffect_max, nquantiles(10) yscale(range(0 0.7)) yticks(0(0.1)0.7) ylabel(`ylab') xtitle("Max treatment effect (pp.)") ytitle("Percent of trials adopted") note("Binscatter with 10 bins") graphregion(color(white))
		graph export "figures/adoption_by_tebin10.pdf", replace

		* Adoption by three bins of treatment effects with forecasts
		local b1 0.19
		local b2 1.7
		qui sum treatmenteffect_max
		local minte `r(min)'
		local maxte `r(max)'
		
		gen byte tebin=0 if treatmenteffect_max<=`b1' & treatmenteffect_max!=.
		replace	 tebin=1 if treatmenteffect_max>`b1' & treatmenteffect_max<=`b2' & treatmenteffect_max!=.
		replace	 tebin=2 if treatmenteffect_max>`b2' & treatmenteffect_max!=.

		tab tebin, gen(tebinind)

		mat bar=J(6,7,.) 
		mat colnames bar = bin p_adopt lb ub N N_adopt N_nadopt

		local r=1
		forvalues s=3(-1)1 {
			qui reg adopt_byte_`s', r
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[_cons]
			mat bar[`r',3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
			mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
			qui count if adopt_byte_`s'!=.
			mat bar[`r',5]=r(N)
			local ++r 
		}

		gen adopt_byte_diff=adopt_byte_3-adopt_byte_1
		qui reg adopt_byte_diff, r
		local pvalF=string(2*ttail(e(df_r),abs(_b[_cons]/_se[_cons])),"%3.2f")

		qui reg adopt_byte_diff
		est sto f
		
		qui reg adopted tebinind1-tebinind3, cl(cityid) nocons
		forvalues t=1/3 {
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[tebinind`t']
			mat bar[`r',3]=_b[tebinind`t']+invttail(e(df_r),0.975)*_se[tebinind`t']
			mat bar[`r',4]=_b[tebinind`t']+invttail(e(df_r),0.025)*_se[tebinind`t']
			qui count if tebinind`t'==1 & adopted !=.
			mat bar[`r',5]=r(N)
			qui count if tebinind`t'==1 & adopted ==1
			mat bar[`r',6]=r(N)
			qui count if tebinind`t'==1 & adopted ==0
			mat bar[`r',7]=r(N)
			local ++r
		}
		qui test tebinind1=tebinind3
		local pvalE=string(`r(p)',"%3.2f")
		
		qui reg adopted tebinind1-tebinind3, nocons
		est sto e

		suest f e, cl(cityid)
		lincom [f_mean]_cons-100*([e_mean]tebinind1-[e_mean]tebinind3)
		local Pval=string(`r(p)',"%3.2f")

		clear
		svmat bar, names(col)
		
		replace p_adopt=p_adopt*100 if bin>3
		replace ub=ub*100 if bin>3
		replace lb=lb*100 if bin>3
		
		tostring p_adopt, gen(barlabel) format("%2.0f") force
		replace barlabel=barlabel+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_adopt, replace format("%3.0f") force
		
		replace barlabel=barlabel+" ("+N_adopt+"/"+N+")"  if bin>3
		replace barlabel=barlabel+" (N="+N+")"  if bin<=3
		
		local maxy=70
		
		egen max=max(p_adopt), by(bin)
		replace max=max+1
		
		sort bin
		gen 	x=_n*0.3
		replace x=x+0.15 if bin>3
		qui sum x
		local mx=`r(max)'+0.15
		
		gen byte zero=0
		
		local group1 1
		local group2 3
		qui sum p_adopt if bin==`group1'
		local y1startF=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startF=`r(max)'+3
		local yendF=max(`y1startF',`y2startF')+10
		qui sum x if bin==`group1'
		local x1F=`r(mean)'
		qui sum x if bin==`group2'
		local x2F=`r(mean)'
		local xcentF=(`x1F'+`x2F')/2
		
		local group1 4
		local group2 6
		qui sum p_adopt if bin==`group1'
		local y1startE=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startE=`r(max)'+3
		local yendE=max(`y1startE',`y2startE')+10
		qui sum x if bin==`group1'
		local x1E=`r(mean)'
		qui sum x if bin==`group2'
		local x2E=`r(mean)'
		local xcentE=(`x1E'+`x2E')/2
		
		qui sum x
		local YstartF=`yendF'+3
		local YstartE=`yendE'+3
		local Yend=max(`yendF',`yendE')+7
		local Xcent=(`xcentE'+`xcentF')/2
		
		twoway 	(bar p_adopt x if bin==1, barwidth(0.25) lcolor(gs10) fcolor(gs12%30)) ///
			(bar p_adopt x if bin==2, barwidth(0.25) lcolor(gs10) fcolor(gs12%50)) ///
			(bar p_adopt x if bin==3, barwidth(0.25) lcolor(gs10) fcolor(gs12%70)) ///
			(bar p_adopt x if bin==4, barwidth(0.25) lcolor(ebblue) fcolor(ebblue%30)) ///
			(bar p_adopt x if bin==5, barwidth(0.25) lcolor(ebblue) fcolor(ebblue%50)) ///
			(bar p_adopt x if bin==6, barwidth(0.25) lcolor(ebblue) fcolor(ebblue%70)) ///
			(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(2.45)) ///
			`rcap' ///
			(pci 	`y1startF' `x1F' `yendF' `x1F'   `y2startF' `x2F' `yendF' `x2F'   `yendF' `x1F' `yendF' `x2F' ///
					`y1startE' `x1E' `yendE' `x1E'   `y2startE' `x2E' `yendE' `x2E'   `yendE' `x1E' `yendE' `x2E' ///
					`YstartF' `xcentF' `Yend' `xcentF'   `YstartE' `xcentE' `Yend' `xcentE'   `Yend' `xcentF' `Yend' `xcentE' ///
					, lcolor(gray%50)) ///
			, ///
			graphregion(color(white) margin(0 0 0 5)) bgcolor(white) ///
			xscale(range(0.15 `mx')) yscale(range(0 `maxy')) yticks(0(10)`maxy') ylabel(0(10)`maxy') ///
			xlabel(0.3 "[`minte', `b1']" 0.6 "(`b1', `b2']" 0.9 "(`b2', `maxte']" 1.35 "[`minte', `b1']" 1.65 "(`b1', `b2']" 1.95 "(`b2', `maxte']", noticks labsize(small)) ///  
			legend(off) ///
			text(`yendF' `xcentF' "{it:p}=`pvalF'", size(small) placement(n)) ///
			text(`yendE' `xcentE' "{it:p}=`pvalE'", size(small) placement(n)) ///
			text(`Yend' `Xcent' "{it:p}=`Pval'", size(small) placement(n)) ///
			xtitle(" " "Max treatment effect bin (pp.)") ytitle("Percent of trials adopted") ///
			text(70 `xcentF' "{bf:Forecasted}", placement(n)) ///
			text(70 `xcentE' "{bf:Observed}", placement(n)) ///
			note()
		graph export "figures/adoption_by_tebin.pdf", replace
		
	}
	{ // 5c
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1
		append using "data/Forecasts.dta"
		replace cityid=_n+1000 if missing(cityid)

		gen	byte tbin=-1 if treatmenteffect_maxt<=0 & treatmenteffect_maxt!=.
		replace	 tbin= 0 if treatmenteffect_maxt>0 & treatmenteffect_maxt<invnorm(0.975) & treatmenteffect_maxt!=.
		replace	 tbin= 1 if treatmenteffect_maxt>=invnorm(0.975) & treatmenteffect_maxt!=.

		label define tbin -1 "Zero or negative" 0 "Positive & insignificant" 1 "Positive & significant"
		label values tbin tbin

		tab tbin, gen(tbinind)

		mat bar=J(6,7,.) 
		mat colnames bar = bin p_adopt lb ub N N_adopt N_nadopt

		local r=1
		forvalues s=3(-1)1 {
			qui reg adopt_bysig_`s', r
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[_cons]
			mat bar[`r',3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
			mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
			qui count if adopt_bysig_`s'!=.
			mat bar[`r',5]=r(N)
			local ++r 
		}

		gen adopt_bysig_diff=adopt_bysig_3-adopt_bysig_1
		qui reg adopt_bysig_diff, r
		local pvalF=string(2*ttail(e(df_r),abs(_b[_cons]/_se[_cons])),"%3.2f")

		qui reg adopt_bysig_diff
		est sto f

		qui reg adopted tbinind1-tbinind3, cl(cityid) nocons
		forvalues t=1/3 {
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[tbinind`t']
			mat bar[`r',3]=_b[tbinind`t']-invnorm(0.975)*_se[tbinind`t']
			mat bar[`r',4]=_b[tbinind`t']+invnorm(0.975)*_se[tbinind`t']
			qui count if tbinind`t'==1 & adopted!=.
			mat bar[`r',5]=r(N)
			qui count if tbinind`t'==1 & adopted==1
			mat bar[`r',6]=r(N)
			qui count if tbinind`t'==1 & adopted==0
			mat bar[`r',7]=r(N)
			local ++r
		}

		qui test tbinind1=tbinind3
		local pvalE=string(`r(p)',"%3.2f")

		qui reg adopted tbinind1-tbinind3, nocons
		est sto e

		suest f e, cl(cityid)
		lincom [f_mean]_cons-100*([e_mean]tbinind1-[e_mean]tbinind3)
		local Pval=string(`r(p)',"%3.2f")

		clear
		svmat bar, names(col)
		
		replace p_adopt=p_adopt*100 if bin>3
		replace ub=ub*100 if bin>3
		replace lb=lb*100 if bin>3
		
		tostring p_adopt, gen(barlabel) format("%2.0f") force
		replace barlabel=barlabel+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_adopt, replace format("%3.0f") force
		
		replace barlabel=barlabel+" ("+N_adopt+"/"+N+")"  if bin>3
		replace barlabel=barlabel+" (N="+N+")"  if bin<=3
		
		qui sum p_adopt
		local maxy=70

		egen max=max(p_adopt), by(bin)
		replace max=max+1
		
		sort bin
		gen 	x=_n*0.3
		replace x=x+0.15 if bin>3
		qui sum x
		local mx=`r(max)'+0.15
		
		gen byte zero=0
		
		local group1 1
		local group2 3
		qui sum p_adopt if bin==`group1'
		local y1startF=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startF=`r(max)'+3
		local yendF=max(`y1startF',`y2startF')+10
		qui sum x if bin==`group1'
		local x1F=`r(mean)'
		qui sum x if bin==`group2'
		local x2F=`r(mean)'
		local xcentF=(`x1F'+`x2F')/2
		
		local group1 4
		local group2 6
		qui sum p_adopt if bin==`group1'
		local y1startE=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startE=`r(max)'+3
		local yendE=max(`y1startE',`y2startE')+10
		qui sum x if bin==`group1'
		local x1E=`r(mean)'
		qui sum x if bin==`group2'
		local x2E=`r(mean)'
		local xcentE=(`x1E'+`x2E')/2
		
		qui sum x
		local YstartF=`yendF'+3
		local YstartE=`yendE'+3
		local Yend=max(`yendF',`yendE')+7
		local Xcent=(`xcentE'+`xcentF')/2
		
		twoway 	(bar p_adopt x if bin==1, barwidth(0.25) lcolor(gs10) fcolor(gs12%30)) ///
				(bar p_adopt x if bin==2, barwidth(0.25) lcolor(gs10) fcolor(gs12%50)) ///
				(bar p_adopt x if bin==3, barwidth(0.25) lcolor(gs10) fcolor(gs12%70)) ///
				(bar p_adopt x if bin==4, barwidth(0.25) lcolor(ebblue) fcolor(ebblue%30)) ///
				(bar p_adopt x if bin==5, barwidth(0.25) lcolor(ebblue) fcolor(ebblue%50)) ///
				(bar p_adopt x if bin==6, barwidth(0.25) lcolor(ebblue) fcolor(ebblue%70)) ///
				(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(2.45)) ///
				`rcap' ///
				(pci 	`y1startF' `x1F' `yendF' `x1F'   `y2startF' `x2F' `yendF' `x2F'   `yendF' `x1F' `yendF' `x2F' ///
						`y1startE' `x1E' `yendE' `x1E'   `y2startE' `x2E' `yendE' `x2E'   `yendE' `x1E' `yendE' `x2E' ///
						`YstartF' `xcentF' `Yend' `xcentF'   `YstartE' `xcentE' `Yend' `xcentE'   `Yend' `xcentF' `Yend' `xcentE' ///
						, lcolor(gray%50)) ///
				, ///
				graphregion(color(white)) bgcolor(white) ///
				xscale(range(0.15 `mx')) yscale(range(0 `maxy')) yticks(0(10)`maxy') ylabel(0(10)`maxy') ///
				xlabel(0.3 `" "Zero or" "negative" "' 0.6 `" "Positive" "insignificant" "' 0.9 `" "Positive" "significant" "' 1.35 `" "Zero or" "negative" "' 1.65 `" "Positive" "insignificant" "' 1.95 `" "Positive" "significant" "', noticks labsize(small)) ///
				legend(off) ///
				text(`yendF' `xcentF' "{it:p}=`pvalF'", size(small) placement(n)) ///
				text(`yendE' `xcentE' "{it:p}=`pvalE'", size(small) placement(n)) ///
				text(`Yend' `Xcent' "{it:p}=`Pval'", size(small) placement(n)) ///
				xtitle(" " "Max {it:t}-stat across treatment arms in trial") ytitle("Percent of trials adopted") ///
				text(`maxy' `xcentF' "{bf:Forecasted}", placement(n)) ///
				text(`maxy' `xcentE' "{bf:Observed}", placement(n)) ///
				note()
		graph export "figures/adoption_by_tbin.pdf", replace
	}
	{ // 5d
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1

		gen armind1=(adopted_which_treatment_arm==3)
		gen armind2=(adopted_which_treatment_arm==1)
		gen armind3=(adopted_which_treatment_arm==2)

		mat bar=J(3,2,.) 
		mat colnames bar = bin N

		forvalues s=1(1)3 {
			mat bar[`s',1]=`s'
			qui count if armind`s'==1
			mat bar[`s',2]=`r(N)'
		}
		
		clear
		svmat bar, names(col)
		drop if bin==.
		
		gen 	x=_n*0.3
		qui sum x
		local mx = `r(max)'+0.15
			
		gen byte zero=0
			
		twoway 	(bar N x, barwidth(0.2) lcolor(midgreen) fcolor(midgreen%30)) ///
				(scatter zero x, msym(none) mlabel(N) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
				, ///
				graphregion(color(white)) bgcolor(white) ///
				xlabel(0.3 `" "Only one treatment" "arm in the trial" "' 0.6 `" "Adopted most" "effective arm" "' 0.9 `" "Did not adopt" "most effective arm*" "', noticks) ///
				xscale(range(0.15 `mx')) yscale(range(0 14)) yticks(0(2)14) ylabel(0(2)14) ///
				xtitle("") ytitle("Number of adopted trials") ///
				legend(off) ///
				note("*In this 1 trial, the adopted arm was not significantly different from the most effective arm," "and the adopted arm was recommended by BIT in the trial report based on a secondary outcome.")
		graph export "figures/which_arm_adopted.pdf", replace
	}
}

****************************************
***FIGURE 6: ADOPTION BY CITY CONTEXT***
****************************************
{
	{ // 6a
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1
		append using "data/Forecasts.dta"
		replace cityid=_n+1000 if missing(cityid)

		mat bar=J(4,7,.) 
		mat colnames bar = bin p_adopt lb ub N N_adopt N_nadopt

		local r=1
		forvalues s=2(-1)1 {
			qui reg adopt_bysize_`s', r
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[_cons]
			mat bar[`r',3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
			mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
			qui count if adopt_bysize_`s'!=.
			mat bar[`r',5]=r(N)
			local ++r 
		}

		gen adopt_bysize_diff=adopt_bysize_2-adopt_bysize_1
		qui reg adopt_bysize_diff, r
		local pvalF=string(2*ttail(e(df_r),abs(_b[_cons]/_se[_cons])),"%3.2f")

		qui reg adopt_bysize_diff
		est sto f
	
		qui reg adopted ibn.pop_abovemed, nocons cl(cityid)
		forvalues s=0/1 {
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[`s'.pop_abovemed]
			mat bar[`r',3]=_b[`s'.pop_abovemed]+invttail(e(df_r),0.975)*_se[`s'.pop_abovemed]
			mat bar[`r',4]=_b[`s'.pop_abovemed]+invttail(e(df_r),0.025)*_se[`s'.pop_abovemed]
			qui count if pop_abovemed==`s' & adopted!=.
			mat bar[`r',5]=r(N)
			qui count if pop_abovemed==`s' & adopted==1
			mat bar[`r',6]=r(N)
			qui count if pop_abovemed==`s' & adopted==0
			mat bar[`r',7]=r(N)
			local ++r
		}

		qui test 0.pop_abovemed=1.pop_abovemed
		local pvalE=string(`r(p)',"%3.2f")

		qui reg adopted ibn.pop_abovemed, nocons
		est sto e

		suest f e, cl(cityid)
		lincom [f_mean]_cons-100*([e_mean]0.pop_abovemed-[e_mean]1.pop_abovemed)
		local Pval=string(`r(p)',"%3.2f")
		
		*qui sum popestimate2020, d // redacted
		*local med = r(p50)
		local med = 562540
		
		clear
		svmat bar, names(col)
		
		replace p_adopt=p_adopt*100 if bin>=3
		replace ub=ub*100 if bin>=3
		replace lb=lb*100 if bin>=3
		
		tostring p_adopt, gen(barlabel) format("%2.0f") force
		replace barlabel=barlabel+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_adopt, replace format("%3.0f") force
		
		replace barlabel=barlabel+" ("+N_adopt+"/"+N+")" if bin>=3
		replace barlabel=barlabel+" (N="+N+")" if bin<3
		
		local maxy=70
			
		egen max=max(p_adopt), by(bin)
		replace max=max+1
		
		sort bin
		gen 	x=_n*0.3
		replace x=x+0.15 if bin>=3
		qui sum x
		local mx=`r(max)'+0.15
		
		local group1 1
		local group2 2
		qui sum p_adopt if bin==`group1'
		local y1startF=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startF=`r(max)'+3
		local yendF=max(`y1startF',`y2startF')+10
		qui sum x if bin==`group1'
		local x1F=`r(mean)'
		qui sum x if bin==`group2'
		local x2F=`r(mean)'
		local xcentF=(`x1F'+`x2F')/2
		
		local group1 3
		local group2 4
		qui sum p_adopt if bin==`group1'
		local y1startE=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startE=`r(max)'+3
		local yendE=max(`y1startE',`y2startE')+10
		qui sum x if bin==`group1'
		local x1E=`r(mean)'
		qui sum x if bin==`group2'
		local x2E=`r(mean)'
		local xcentE=(`x1E'+`x2E')/2
		
		qui sum x
		local YstartF=`yendF'+3
		local YstartE=`yendE'+3
		local Yend=max(`yendF',`yendE')+7
		local Xcent=(`xcentE'+`xcentF')/2
		
		gen byte zero=0
		
		twoway 	(bar p_adopt x if bin==1, barwidth(0.2) lcolor(gs10) fcolor(gs12%50)) ///
				(bar p_adopt x if bin==2, barwidth(0.2) lcolor(gs10) fcolor(gs12)) ///
				(bar p_adopt x if bin==3, barwidth(0.2) lcolor(ebblue) fcolor(ebblue%50)) /// 
				(bar p_adopt x if bin==4, barwidth(0.2) lcolor(ebblue) fcolor(ebblue)) /// 
				`rcap' ///
				(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
				(pci 	`y1startF' `x1F' `yendF' `x1F'   `y2startF' `x2F' `yendF' `x2F'   `yendF' `x1F' `yendF' `x2F' ///
						`y1startE' `x1E' `yendE' `x1E'   `y2startE' `x2E' `yendE' `x2E'   `yendE' `x1E' `yendE' `x2E' ///
						`YstartF' `xcentF' `Yend' `xcentF'   `YstartE' `xcentE' `Yend' `xcentE'   `Yend' `xcentF' `Yend' `xcentE' ///
						, lcolor(gray%50)) ///
				, ///
				graphregion(color(white)) bgcolor(white) ///
				xscale(range(0.15 `mx')) yscale(range(0 `maxy')) yticks(0(10)`maxy') ylabel(0(10)`maxy') ///
				xlabel(0.3 "{it:Below}" 0.6 "{it:Above}" 1.05 "{it:Below}" 1.35 "{it:Above}", noticks) ///
				legend(off) ///
				text(`yendF' `xcentF' "{it:p}=`pvalF'", size(small) placement(n)) ///
				text(`yendE' `xcentE' "{it:p}=`pvalE'", size(small) placement(n)) ///
				text(`Yend' `Xcent' "{it:p}=`Pval'", size(small) placement(n)) ///
				xtitle(" " "{bf:Trial in city below or above the median size in by 2020 population?}") ytitle("Percent of trials adopted") ///
				text(`maxy' `xcentF' "{bf:Forecasted}", placement(n)) ///
				text(`maxy' `xcentE' "{bf:Observed}", placement(n)) ///
				note("Median city population: `med'")
		graph export "figures/adoption_by_citypop.pdf", replace
	}
	{ // 6b
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1
		append using "data/Forecasts.dta"
		replace cityid=_n+1000 if missing(cityid)

		mat bar=J(4,7,.) 
		mat colnames bar = bin p_adopt lb ub N N_adopt N_nadopt

		local r=1
		forvalues s=2(-1)1 {
			qui reg adopt_byWWC_`s', r
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[_cons]
			mat bar[`r',3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
			mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
			qui count if adopt_byWWC_`s'!=.
			mat bar[`r',5]=r(N)
			local ++r 
		}

		gen adopt_byWWC_diff=adopt_byWWC_2-adopt_byWWC_1
		qui reg adopt_byWWC_diff, r
		local pvalF=string(2*ttail(e(df_r),abs(_b[_cons]/_se[_cons])),"%3.2f")

		qui reg adopt_byWWC_diff
		est sto f
		
		qui reg adopted ibn.WWC_cert, nocons cl(cityid)
		forvalues s=0/1 {
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[`s'.WWC_cert]
			mat bar[`r',3]=_b[`s'.WWC_cert]+invttail(e(df_r),0.975)*_se[`s'.WWC_cert]
			mat bar[`r',4]=_b[`s'.WWC_cert]+invttail(e(df_r),0.025)*_se[`s'.WWC_cert]
			qui count if WWC_cert==`s' & adopted!=.
			mat bar[`r',5]=r(N)
			qui count if WWC_cert==`s' & adopted==1
			mat bar[`r',6]=r(N)
			qui count if WWC_cert==`s' & adopted==0
			mat bar[`r',7]=r(N)
			local ++r
		}

		qui reg adopted ibn.WWC_cert, nocons cl(cityid)
		qui test 0.WWC_cert=1.WWC_cert
		local pvalE=string(`r(p)',"%3.2f")

		qui reg adopted ibn.WWC_cert, nocons
		est sto e

		suest f e, cl(cityid)
		lincom [f_mean]_cons-100*([e_mean]0.WWC_cert-[e_mean]1.WWC_cert)
		local Pval=string(`r(p)',"%3.2f")

		clear
		svmat bar, names(col)
		
		replace p_adopt=p_adopt*100 if bin>=3
		replace ub=ub*100 if bin>=3
		replace lb=lb*100 if bin>=3
		
		tostring p_adopt, gen(barlabel) format("%2.0f") force
		replace barlabel=barlabel+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_adopt, replace format("%3.0f") force
		
		replace barlabel=barlabel+" ("+N_adopt+"/"+N+")" if bin>=3
		replace barlabel=barlabel+" (N="+N+")" if bin<3
		
		local maxy 70
		
		egen max=max(p_adopt), by(bin)
		replace max=max+1
		
		sort bin
		gen 	x=_n*0.3
		replace x=x+0.15 if bin>=3
		qui sum x
		local mx=`r(max)'+0.15
		
		local group1 1
		local group2 2
		qui sum p_adopt if bin==`group1'
		local y1startF=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startF=`r(max)'+3
		local yendF=max(`y1startF',`y2startF')+10
		qui sum x if bin==`group1'
		local x1F=`r(mean)'
		qui sum x if bin==`group2'
		local x2F=`r(mean)'
		local xcentF=(`x1F'+`x2F')/2
		
		local group1 3
		local group2 4
		qui sum p_adopt if bin==`group1'
		local y1startE=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startE=`r(max)'+3
		local yendE=max(`y1startE',`y2startE')+10
		qui sum x if bin==`group1'
		local x1E=`r(mean)'
		qui sum x if bin==`group2'
		local x2E=`r(mean)'
		local xcentE=(`x1E'+`x2E')/2
		
		qui sum x
		local YstartF=`yendF'+3
		local YstartE=`yendE'+3
		local Yend=max(`yendF',`yendE')+7
		local Xcent=(`xcentE'+`xcentF')/2
		
		gen byte zero=0
		
		twoway 	(bar p_adopt x if bin==1, barwidth(0.2) lcolor(gs10) fcolor(gs12%50)) ///
				(bar p_adopt x if bin==2, barwidth(0.2) lcolor(gs10) fcolor(gs12)) ///
				(bar p_adopt x if bin==3, barwidth(0.2) lcolor(ebblue) fcolor(ebblue%50)) /// 
				(bar p_adopt x if bin==4, barwidth(0.2) lcolor(ebblue) fcolor(ebblue)) /// 
				`rcap' ///
				(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
				(pci 	`y1startF' `x1F' `yendF' `x1F'   `y2startF' `x2F' `yendF' `x2F'   `yendF' `x1F' `yendF' `x2F' ///
						`y1startE' `x1E' `yendE' `x1E'   `y2startE' `x2E' `yendE' `x2E'   `yendE' `x1E' `yendE' `x2E' ///
						`YstartF' `xcentF' `Yend' `xcentF'   `YstartE' `xcentE' `Yend' `xcentE'   `Yend' `xcentF' `Yend' `xcentE' ///
						, lcolor(gray%50)) ///
				, ///
				graphregion(color(white)) bgcolor(white) ///
				xscale(range(0.15 `mx')) yscale(range(0 `maxy')) yticks(0(10)`maxy') ylabel(0(10)`maxy') ///
				xlabel(0.3 "{it:Not certified}" 0.6 "{it:Certified}" 1.05 "{it:Not certified}" 1.35 "{it:Certified}", noticks) ///
				legend(off) ///
				text(`yendF' `xcentF' "{it:p}=`pvalF'", size(small) placement(n)) ///
				text(`yendE' `xcentE' "{it:p}=`pvalE'", size(small) placement(n)) ///
				text(`Yend' `Xcent' "{it:p}=`Pval'", size(small) placement(n)) ///
				xtitle(" " "{bf:Trial in city certified by the What Works Cities Program?}") ytitle("Percent of trials adopted") ///
				text(`maxy' `xcentF' "{bf:Forecasted}", placement(n)) ///
				text(`maxy' `xcentE' "{bf:Observed}", placement(n)) ///
				note()
		graph export "figures/adoption_by_WWC.pdf", replace
	}
	{ // 6c
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1
		append using "data/Forecasts.dta"
		replace cityid=_n+1000 if missing(cityid)

		mat bar=J(4,7,.) 
		mat colnames bar = bin p_adopt lb ub N N_adopt N_nadopt

		local r=1
		forvalues s=2(-1)1 {
			qui reg adopt_bystaff_`s', r
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[_cons]
			mat bar[`r',3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
			mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
			qui count if adopt_bystaff_`s'!=.
			mat bar[`r',5]=r(N)
			local ++r 
		}

		gen adopt_bystaff_diff=adopt_bystaff_2-adopt_bystaff_1
		qui reg adopt_bystaff_diff, r
		local pvalF=string(2*ttail(e(df_r),abs(_b[_cons]/_se[_cons])),"%3.2f")

		qui reg adopt_bystaff_diff
		est sto f
		
		qui reg adopted ibn.staff_same_dpt, nocons cl(cityid)
		forvalues s=0/1 {
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[`s'.staff_same_dpt]
			mat bar[`r',3]=_b[`s'.staff_same_dpt]+invttail(e(df_r),0.975)*_se[`s'.staff_same_dpt]
			mat bar[`r',4]=_b[`s'.staff_same_dpt]+invttail(e(df_r),0.025)*_se[`s'.staff_same_dpt]
			qui count if staff_same_dpt==`s' & adopted !=.
			mat bar[`r',5]=r(N)
			qui count if staff_same_dpt==`s' & adopted ==1
			mat bar[`r',6]=r(N)
			qui count if staff_same_dpt==`s' & adopted ==0
			mat bar[`r',7]=r(N)
			local ++r
		}

		qui reg adopted ibn.staff_same_dpt, nocons cl(cityid)
		qui test 0.staff_same_dpt=1.staff_same_dpt
		local pvalE=string(`r(p)',"%3.2f")

		qui reg adopted ibn.staff_same_dpt, nocons
		est sto e

		suest f e, cl(cityid)
		lincom [f_mean]_cons-100*([e_mean]0.staff_same_dpt-[e_mean]1.staff_same_dpt)
		local Pval=string(`r(p)',"%3.2f")

		clear
		svmat bar, names(col)
		
		replace p_adopt=p_adopt*100 if bin>=3
		replace ub=ub*100 if bin>=3
		replace lb=lb*100 if bin>=3
		
		tostring p_adopt, gen(barlabel) format("%2.0f") force
		replace barlabel=barlabel+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_adopt, replace format("%3.0f") force
		
		replace barlabel=barlabel+" ("+N_adopt+"/"+N+")" if bin>=3
		replace barlabel=barlabel+" (N="+N+")" if bin<3
		
		local maxy 70
		
		egen max=max(p_adopt), by(bin)
		replace max=max+1
		
		sort bin
		gen 	x=_n*0.3
		replace x=x+0.15 if bin>=3
		qui sum x
		local mx=`r(max)'+0.15
		
		*pvals
		local group1 1
		local group2 2
		qui sum p_adopt if bin==`group1'
		local y1startF=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startF=`r(max)'+3
		local yendF=max(`y1startF',`y2startF')+10
		qui sum x if bin==`group1'
		local x1F=`r(mean)'
		qui sum x if bin==`group2'
		local x2F=`r(mean)'
		local xcentF=(`x1F'+`x2F')/2
		
		local group1 3
		local group2 4
		qui sum p_adopt if bin==`group1'
		local y1startE=`r(max)'+3
		qui sum p_adopt if bin==`group2'
		local y2startE=`r(max)'+3
		local yendE=max(`y1startE',`y2startE')+10
		qui sum x if bin==`group1'
		local x1E=`r(mean)'
		qui sum x if bin==`group2'
		local x2E=`r(mean)'
		local xcentE=(`x1E'+`x2E')/2
		
		qui sum x
		local YstartF=`yendF'+3
		local YstartE=`yendE'+3
		local Yend=max(`yendF',`yendE')+7
		local Xcent=(`xcentE'+`xcentF')/2
		
		gen byte zero=0
		
		twoway 	(bar p_adopt x if bin==1, barwidth(0.2) lcolor(gs10) fcolor(gs12%50)) ///
				(bar p_adopt x if bin==2, barwidth(0.2) lcolor(gs10) fcolor(gs12)) ///
				(bar p_adopt x if bin==3, barwidth(0.2) lcolor(ebblue) fcolor(ebblue%50)) /// 
				(bar p_adopt x if bin==4, barwidth(0.2) lcolor(ebblue) fcolor(ebblue)) /// 
				(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
				`rcap' ///
				(pci 	`y1startF' `x1F' `yendF' `x1F'  `y2startF' `x2F' `yendF' `x2F'  `yendF' `x1F' `yendF' `x2F' ///
						`y1startE' `x1E' `yendE' `x1E'  `y2startE' `x2E' `yendE' `x2E'  `yendE' `x1E' `yendE' `x2E' ///
						`YstartF' `xcentF' `Yend' `xcentF'  `YstartE' `xcentE' `Yend' `xcentE'  `Yend' `xcentF' `Yend' `xcentE' ///
						, lcolor(gray%50)) ///
				, ///
				graphregion(color(white)) bgcolor(white) ///
				xscale(range(0.15 `mx')) yscale(range(0 `maxy')) yticks(0(10)`maxy') ylabel(0(10)`maxy') ///
				xlabel(0.3 "{it:Not retained}" 0.6 "{it:Retained}" 1.05 "{it:Not retained}" 1.35 "{it:Retained}", noticks) ///
				legend(off) ///
				text(`yendF' `xcentF' "{it:p}=`pvalF'", size(small) placement(n)) ///
				text(`yendE' `xcentE' "{it:p}=`pvalE'", size(small) placement(n)) ///
				text(`Yend' `Xcent' "{it:p}=`Pval'", size(small) placement(n)) ///
				xtitle(" " "{bf:Original city collaborator still employed by the same city department?}") ytitle("Percent of trials adopted") ///
				text(`maxy' `xcentF' "{bf:Forecasted}", placement(n)) ///
				text(`maxy' `xcentE' "{bf:Observed}", placement(n)) ///
				note()
		graph export "figures/adoption_by_staff.pdf", replace
	}
}

***********************************************
***FIGURE 7: ADOPTION BY EXPERIMENTAL DESIGN***
***********************************************
{
	{ // 7a
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1
		append using "data/Forecasts.dta"
		replace cityid=_n+1000 if missing(cityid)

		gen byte mechbin1=(mech_simplification==1)
		gen byte mechbin2=(mech_personalmotivation==1)
		gen byte mechbin3=(mech_socialcues==1)
		gen byte mechbin23=(mech_personalmotivation==1 | mech_socialcues==1)
		gen byte mechbin4=(mech_simplification+mech_personalmotivation+mech_socialcues==0)

		mat bar=J(6,7,.) 
		mat colnames bar = bin p_adopt lb ub N N_adopt N_nadopt

		local r=1
		forvalues s=1(1)3 {
			qui reg adopt_bymech_`s', r
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[_cons]
			mat bar[`r',3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
			mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
			qui count if adopt_bymech_`s'!=.
			mat bar[`r',5]=r(N)
			local ++r 
		}

		gen adopt_bymech_diff=adopt_bymech_1-(adopt_bymech_2+adopt_bymech_3)/2 // average of the other two
		qui reg adopt_bymech_diff, r
		local pvalF=string(2*ttail(e(df_r),abs(_b[_cons]/_se[_cons])),"%3.2f")

		qui reg adopt_bymech_diff
		est sto f

		forvalues s=1/3 {
			qui reg adopted if mechbin`s'==1, cl(cityid)
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[_cons]
			mat bar[`r',3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
			mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
			qui count if mechbin`s'==1 & adopted !=.
			mat bar[`r',5]=r(N)
			qui count if mechbin`s'==1 & adopted ==1
			mat bar[`r',6]=r(N)
			qui count if mechbin`s'==1 & adopted ==0
			mat bar[`r',7]=r(N)
			local ++r
		}

		qui reg adopted mechbin1 if mechbin1==1 | mechbin23==1, cl(cityid)
		qui test mechbin1=0
		local pvalE=string(`r(p)',"%3.2f")

		qui reg adopted mechbin1 if mechbin1==1 | mechbin23==1
		est sto e

		suest f e, cl(cityid)
		lincom [f_mean]_cons-100*([e_mean]mechbin1)
		local Pval=string(`r(p)',"%3.2f")
		
		clear
		svmat bar, names(col)
		
		replace p_adopt=p_adopt*100 if bin>3
		replace ub=ub*100 if bin>3
		replace lb=lb*100 if bin>3
		
		tostring p_adopt, gen(barlabel) format("%2.0f") force
		replace barlabel=barlabel+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_adopt, replace format("%3.0f") force
		
		replace barlabel=barlabel+" ("+N_adopt+"/"+N+")" if bin>3
		replace barlabel=barlabel+" (N="+N+")" if bin<=3
		
		local maxy 70
		
		egen max=max(p_adopt), by(bin)
		replace max=max+1
		
		sort bin
		gen 	x=_n*0.3
		replace x=x+0.15 if bin>3
		qui sum x
		local mx=`r(max)'+0.15
		
		local subgroupA 2
		local subgroupB 3
		qui sum p_adopt if bin==`subgroupA'
		local y1startFs=`r(max)'+3
		qui sum p_adopt if bin==`subgroupB'
		local y2startFs=`r(max)'+3
		local yendFs=max(`y1startFs',`y2startFs')+5
		qui sum x if bin==`subgroupA'
		local x1Fs=`r(mean)'
		qui sum x if bin==`subgroupB'
		local x2Fs=`r(mean)'
		local xcentFs=(`x1Fs'+`x2Fs')/2
		
		local group 1
		qui sum p_adopt if bin==`group'
		local y1startF=`r(max)'+3
		local yendF=max(`y1startF',`yendFs')+5
		qui sum x if bin==`group'
		local x1F=`r(mean)'
		local xcentF=(`x1F'+`xcentFs')/2
		
		local subgroupA 5
		local subgroupB 6
		qui sum p_adopt if bin==`subgroupA'
		local y1startEs=`r(max)'+3
		qui sum p_adopt if bin==`subgroupB'
		local y2startEs=`r(max)'+3
		local yendEs=max(`y1startEs',`y2startEs')+5
		qui sum x if bin==`subgroupA'
		local x1Es=`r(mean)'
		qui sum x if bin==`subgroupB'
		local x2Es=`r(mean)'
		local xcentEs=(`x1Es'+`x2Es')/2
		
		local group 4
		qui sum p_adopt if bin==`group'
		local y1startE=`r(max)'+3
		local yendE=max(`y1startE',`yendEs')+5
		qui sum x if bin==`group'
		local x1E=`r(mean)'
		local xcentE=(`x1E'+`xcentEs')/2
		
		qui sum x
		local YstartF=`yendF'+3
		local YstartE=`yendE'+3
		local Yend=max(`yendF',`yendE')+7
		local Xcent=(`xcentE'+`xcentF')/2
		
		gen byte zero=0
		
		twoway 	(bar p_adopt x if bin==1, barwidth(0.25) lcolor(gs10) fcolor(gs12%30)) ///
				(bar p_adopt x if bin==2, barwidth(0.25) lcolor(gs10) fcolor(gs12%50)) ///
				(bar p_adopt x if bin==3, barwidth(0.25) lcolor(gs10) fcolor(gs12%70)) ///
				(bar p_adopt x if bin==4, barwidth(0.25) lcolor(ebblue) fcolor(ebblue%30)) ///
				(bar p_adopt x if bin==5, barwidth(0.25) lcolor(ebblue) fcolor(ebblue%50)) ///
				(bar p_adopt x if bin==6, barwidth(0.25) lcolor(ebblue) fcolor(ebblue%70)) ///
				(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(2.45)) ///
				`rcap' ///
				(pci 	`y1startFs' `x1Fs' `yendFs' `x1Fs'  `y2startFs' `x2Fs' `yendFs' `x2Fs'  `yendFs' `x1Fs' `yendFs' `x2Fs' ///
						`y1startF' `x1F' `yendF' `x1F'  `yendFs' `xcentFs' `yendF' `xcentFs'  `yendF' `x1F' `yendF' `xcentFs'	///
						`y1startEs' `x1Es' `yendEs' `x1Es'  `y2startEs' `x2Es' `yendEs' `x2Es'  `yendEs' `x1Es' `yendEs' `x2Es' ///
						`y1startE' `x1E' `yendE' `x1E'  `yendEs' `xcentEs' `yendE' `xcentEs'  `yendE' `x1E' `yendE' `xcentEs'	///
						`YstartF' `xcentF' `Yend' `xcentF'  `YstartE' `xcentE' `Yend' `xcentE'  `Yend' `xcentF' `Yend' `xcentE' ///
						, lcolor(gray%50)) ///
				, ///
				graphregion(color(white)) bgcolor(white) ///
				xscale(range(0.15 `mx')) yscale(range(0 `maxy')) yticks(0(10)`maxy') ylabel(0(10)`maxy') ///
				xlabel(0.3 "{it:Simplification}" 0.6 `" "{it:Personal}" "{it:motivation}" "' 0.9 "{it:Social cues}" 1.35 "{it:Simplification}" 1.65 `" "{it:Personal}" "{it:motivation}" "' 1.95 "{it:Social cues}", noticks labsize(small)) ///
				legend(off) ///
				text(`yendF' `xcentF' "{it:p}=`pvalF'", size(small) placement(n)) ///
				text(`yendE' `xcentE' "{it:p}=`pvalE'", size(small) placement(n)) ///
				text(`Yend' `Xcent' "{it:p}=`Pval'", size(small) placement(n)) ///
				xtitle(" " "{bf:Behavioral mechanism used in trial nudges}") ytitle("Percent of trials adopted") ///
				text(`maxy' 0.6 "{bf:Forecasted}", placement(n)) ///
				text(`maxy' 1.65 "{bf:Observed}", placement(n)) ///
				note("Mechanisms are not mutually exclusive" )
		graph export "figures/adoption_by_mech.pdf", replace
	}
	{ // 7b
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1
		append using "data/Forecasts.dta"
		replace cityid=_n+1000 if missing(cityid)

		mat bar=J(4,7,.) 
		mat colnames bar = bin p_adopt lb ub N N_adopt N_nadopt

		local r=1
		forvalues s=1(1)2 {
			qui reg adopt_bypreexist_`s', r
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[_cons]
			mat bar[`r',3]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
			mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
			qui count if adopt_bypreexist_`s'!=.
			mat bar[`r',5]=r(N)
			local ++r 
		}

		gen adopt_bypreexist_diff=adopt_bypreexist_2-adopt_bypreexist_1
		qui reg adopt_bypreexist_diff, r
		local pvalF=string(2*ttail(e(df_r),abs(_b[_cons]/_se[_cons])),"%3.2f")

		qui reg adopt_bypreexist_diff
		est sto f

		qui reg adopted ibn.comm_preexisted, nocons cl(cityid)
		forvalues s=0/1 {
			mat bar[`r',1]=`r'
			mat bar[`r',2]=_b[`s'.comm_preexisted]
			mat bar[`r',3]=_b[`s'.comm_preexisted]+invttail(e(df_r),0.975)*_se[`s'.comm_preexisted]
			mat bar[`r',4]=_b[`s'.comm_preexisted]+invttail(e(df_r),0.025)*_se[`s'.comm_preexisted]
			qui count if comm_preexisted==`s' & adopted !=.
			mat bar[`r',5]=r(N)
			qui count if comm_preexisted==`s' & adopted ==1
			mat bar[`r',6]=r(N)
			qui count if comm_preexisted==`s' & adopted ==0
			mat bar[`r',7]=r(N)
			local ++r
		}

		qui test 0.comm_preexisted=1.comm_preexisted
		local pvalE=string(`r(p)',"%3.2f")

		qui reg adopted ibn.comm_preexisted, nocons
		est sto e

		suest f e, cl(cityid)
		lincom [f_mean]_cons-100*([e_mean]1.comm_preexisted-[e_mean]0.comm_preexisted)
		local Pval=string(`r(p)',"%3.2f")

		clear
		svmat bar, names(col)
		
		replace p_adopt=p_adopt*100 if bin>=3
		replace ub=ub*100 if bin>=3
		replace lb=lb*100 if bin>=3
		
		tostring p_adopt, gen(barlabel) format("%2.0f") force
		replace barlabel=barlabel+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_adopt, replace format("%3.0f") force
		
		replace barlabel=barlabel+" ("+N_adopt+"/"+N+")" if bin>=3
		replace barlabel=barlabel+" (N="+N+")" if bin<3
		
		local maxy 70
		
		egen max=max(p_adopt), by(bin)
		replace max=max+1
		
		sort bin
		gen 	x=_n*0.3
		replace x=x+0.15 if bin>=3
		qui sum x
		local mx=`r(max)'+0.15
		
		local group1 1
		local group2 2
		qui sum p_adopt if bin==`group1'
		local y1startF=`r(max)'+1
		qui sum p_adopt if bin==`group2'
		local y2startF=`r(max)'+1
		local yendF=max(`y1startF',`y2startF')+3
		qui sum x if bin==`group1'
		local x1F=`r(mean)'
		qui sum x if bin==`group2'
		local x2F=`r(mean)'
		local xcentF=(`x1F'+`x2F')/2
		
		local group1 3
		local group2 4
		qui sum p_adopt if bin==`group1'
		local y1startE=`r(max)'+2
		qui sum p_adopt if bin==`group2'
		local y2startE=`r(max)'+2
		local yendE=max(`y1startE',`y2startE')+3
		qui sum x if bin==`group1'
		local x1E=`r(mean)'
		qui sum x if bin==`group2'
		local x2E=`r(mean)'
		local xcentE=(`x1E'+`x2E')/2
		
		qui sum x
		local YstartF=`yendF'+3
		local YstartE=`yendE'+3
		local Yend=max(`yendF',`yendE')+5
		local Xcent=(`xcentE'+`xcentF')/2
		
		gen byte zero=0
		
		twoway 	(bar p_adopt x if bin==1, barwidth(0.2) lcolor(gs10) fcolor(gs12%50)) ///
				(bar p_adopt x if bin==2, barwidth(0.2) lcolor(gs10) fcolor(gs12)) ///
				(bar p_adopt x if bin==3, barwidth(0.2) lcolor(ebblue) fcolor(ebblue%50)) /// 
				(bar p_adopt x if bin==4, barwidth(0.2) lcolor(ebblue) fcolor(ebblue)) /// 
				(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
				`rcap' ///
				(pci 	`y1startF' `x1F' `yendF' `x1F'  `y2startF' `x2F' `yendF' `x2F'  `yendF' `x1F' `yendF' `x2F' ///
						`y1startE' `x1E' `yendE' `x1E'  `y2startE' `x2E' `yendE' `x2E'  `yendE' `x1E' `yendE' `x2E' ///
						`YstartF' `xcentF' `Yend' `xcentF'  `YstartE' `xcentE' `Yend' `xcentE'  `Yend' `xcentF' `Yend' `xcentE' ///
						, lcolor(gray%50)) ///
				, ///
				graphregion(color(white) margin(0 0 0 5)) bgcolor(white) ///
				xlabel(0.3 "{it:New}" 0.6 "{it:Pre-existing}" 1.05 "{it:New}" 1.35 "{it:Pre-existing}", noticks) ///
				xscale(range(0.15 `mx')) yscale(range(0 `maxy')) yticks(0(10)`maxy') ylabel(0(10)`maxy') ///
				legend(off) ///
				text(`yendF' `xcentF' "{it:p}=`pvalF'", size(small) placement(n)) ///
				text(`yendE' `xcentE' "{it:p}=`pvalE'", size(small) placement(n)) ///
				text(`Yend' `Xcent' "{it:p}=`Pval'", size(small) placement(n)) ///
				xtitle(" " "{bf:Communication in trial existed before the trial?}") ytitle("Percent of trials adopted") ///
				text(77.5 `xcentF' "{bf:Forecasted}", placement(n)) ///
				text(77.5 `xcentE' "{bf:Observed}", placement(n)) ///
				note()			
		graph export "figures/adoption_by_preexist.pdf", replace
	}
}

***********************************************
***FIGURE 8: MECHANISMS BEHIND PRE-EXISTENCE***
***********************************************
{
	{ // 8a
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1

		gen byte mediumbin1=(medium_mailer==1 & medium_online==0)
		gen byte mediumbin2=(medium_online==1 & medium_mailer==0)

		mat bar=J(4,8,.) 
		mat colnames bar = bin1 bin2 p_adopt lb ub N N_adopt N_nadopt

		local r=1
		forvalues s=1/2 {
			forvalues t=0/1 {
				qui reg adopted ibn.comm_preexisted if mediumbin`s'==1, nocons cl(cityid)
				mat bar[`r',1]=`s'-1
				mat bar[`r',2]=`t'
				mat bar[`r',3]=_b[`t'.comm_preexisted]
				mat bar[`r',4]=_b[`t'.comm_preexisted]+invttail(e(df_r),0.975)*_se[`t'.comm_preexisted]
				mat bar[`r',5]=_b[`t'.comm_preexisted]+invttail(e(df_r),0.025)*_se[`t'.comm_preexisted]
				qui count if mediumbin`s'==1 & comm_preexisted==`t' & adopted!=.
				mat bar[`r',6]=r(N)
				qui count if mediumbin`s'==1 & comm_preexisted==`t' & adopted==1
				mat bar[`r',7]=r(N)
				qui count if mediumbin`s'==1 & comm_preexisted==`t' & adopted==0
				mat bar[`r',8]=r(N)
				local ++r
			}
		}

		qui reg adopted 1.comm_preexisted if mediumbin1==1, cl(cityid)
		local pval0=string(2*ttail(e(df_r),abs(_b[1.comm_preexisted]/_se[1.comm_preexisted])),"%3.2f")
		
		qui tab comm_preexisted adopted if mediumbin2==1, exact
		local pval1=string(`r(p_exact)',"%3.2f")
		qui reg adopted 1.comm_preexisted##1.mediumbin2 if mediumbin1==1 | mediumbin2==1, cl(cityid)
		local pvald=string(2*ttail(e(df_r),abs(_b[1.comm_preexisted#1.mediumbin2]/_se[1.comm_preexisted#1.mediumbin2])),"%3.2f")

		clear
		svmat bar, names(col)
		
		replace p_adopt=p_adopt*100
		replace ub=ub*100
		replace lb=lb*100
		
		tostring p_adopt, gen(barlabel) format("%2.0f") force
		replace barlabel=barlabel+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_adopt, replace format("%3.0f") force
		
		replace barlabel=barlabel+" ("+N_adopt+"/"+N+")"
		
		local maxy 100
		
		egen max=max(p_adopt), by(bin1 bin2)
		replace max=max+1
		
		sort bin1 bin2
		gen 	x=_n*0.3+bin1*0.2
		qui sum x
		local mx=`r(max)'+0.15
		
		qui sum max if bin1==0
		local yend0=`r(max)'+5
		qui sum p_adopt if bin1==1
		local yend1=`r(max)'+5
		qui sum p_adopt if bin1==0 & bin2==0
		local ystart00=`r(max)'+2
		qui sum p_adopt if bin1==0 & bin2==1
		local ystart01=`r(max)'+2
		qui sum p_adopt if bin1==1 & bin2==0
		local ystart10=`r(max)'+2
		qui sum p_adopt if bin1==1 & bin2==1
		local ystart11=`r(max)'+2
		qui sum x if bin1==0
		local xstart0=`r(min)'
		local xend0=`r(max)'
		local xcent0=`r(mean)'
		qui sum x if bin1==1
		local xstart1=`r(min)'
		local xend1=`r(max)'
		local xcent1=`r(mean)'
		local Ystart0=`yend0'+4
		local Ystart1=`yend1'+4
		local Yend=max(`yend0',`yend1')+5
		local Xcent=(`xcent0'+`xcent1')/2
		
		gen byte zero=0
		
		twoway 	(bar p_adopt x if bin1==0 & bin2==0, barwidth(0.2) lcolor(orange_red) fcolor(orange_red%30)) ///
				(bar p_adopt x if bin1==0 & bin2==1, barwidth(0.2) lcolor(midgreen) fcolor(midgreen%70)) ///
				(bar p_adopt x if bin1==1 & bin2==0, barwidth(0.2) lcolor(orange_red) fcolor(orange_red%30)) ///
				(bar p_adopt x if bin1==1 & bin2==1, barwidth(0.2) lcolor(midgreen) fcolor(midgreen%70)) ///
				`rcap' ///
				(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
				(pci 	`ystart00' `xstart0' `yend0' `xstart0'  `ystart01' `xend0' `yend0' `xend0'  `yend0' `xstart0' `yend0' `xend0' ///
						`ystart10' `xstart1' `yend1' `xstart1'  `ystart11' `xend1' `yend1' `xend1'  `yend1' `xstart1' `yend1' `xend1' ///
						`Ystart0' `xcent0' `Yend' `xcent0'  `Ystart1' `xcent1' `Yend' `xcent1'  `Yend' `xcent0' `Yend' `xcent1' ///
						, lcolor(gray%50)) ///
				, ///
				text(`Ystart0' `xcent0' "{it:p}=`pval0'", size(small) placement(s)) ///
				text(`Ystart1' `xcent1' "{it:p}=`pval1'*", size(small) placement(s)) /// 
				text(`Yend' `Xcent' "{it:p}=`pvald'", size(small) placement(n)) ///
				text(`maxy' `xcent0' "{bf:Only physical mailers}", placement(n)) ///
				text(`maxy' `xcent1' "{bf:Only online/texts}", placement(n)) ///
				graphregion(color(white)) bgcolor(white) ///
				xscale(range(0.15 `mx')) yscale(range(0 `maxy')) yticks(0(10)`maxy') ylabel(0(10)`maxy') ///
				xlabel(0.3 "{it:New}" 0.6 "{it:Pre-existing}" 1.1 "{it:New}" 1.4 "{it:Pre-existing}", noticks) ///
				legend(off) ///
				xtitle(" " "{bf:Communication in trial existed before the trial?}") ytitle("Percent of trials adopted") ///
				note("*Calculated using Fisher's exact test" )
		graph export "figures/adoption_by_med_preexist.pdf", replace
	}
	{ // 8b
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1
		
		mat bar=J(2,5,.) 
		mat colnames bar = bin1 N N_senttreat N_sentcontrol N_sentnone

		local r=1
		forvalues s=0/1 {
			mat bar[`r',1]=`s'
			
			qui count if comm_preexisted==`s'
			mat bar[`r',2]=`r(N)'
			
			qui count if comm_preexisted==`s' & adopted==1
			mat bar[`r',3]=`r(N)'
			
			qui count if comm_preexisted==`s' & adopted_control_comm==1
			mat bar[`r',4]=`r(N)'
			
			qui count if comm_preexisted==`s' & adopted==0 & adopted_control_comm!=1
			mat bar[`r',5]=`r(N)'
			
			local ++r
		}

		clear
		svmat bar, names(col)
		
		gen P_senttreat = N_senttreat*100 / N
		gen P_sentcontrol = (N_sentcontrol*100 / N) + P_senttreat
		gen P_sentnone = (N_sentnone*100 / N) + P_sentcontrol
		
		gen P_senttreat_lab = N_senttreat*100 / N
		gen P_sentcontrol_lab = N_sentcontrol*100 / N
		gen P_sentnone_lab = N_sentnone*100 / N
		
		tostring P_senttreat_lab, replace format("%2.0f") force
		replace P_senttreat_lab=P_senttreat_lab+"%"
		tostring P_sentcontrol_lab, replace format("%2.0f") force
		replace P_sentcontrol_lab=P_sentcontrol_lab+"%"
		tostring P_sentnone_lab, replace format("%2.0f") force
		replace P_sentnone_lab=P_sentnone_lab+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_senttreat, replace format("%3.0f") force
		tostring N_sentcontrol, replace format("%3.0f") force
		tostring N_sentnone, replace format("%3.0f") force
		
		replace P_senttreat_lab=P_senttreat_lab+" ("+N_senttreat+"/"+N+")"
		replace P_sentcontrol_lab=P_sentcontrol_lab+" ("+N_sentcontrol+"/"+N+")"
		replace P_sentnone_lab=P_sentnone_lab+" ("+N_sentnone+"/"+N+")"
		
		gen P_senttreat_labpos=P_senttreat/2
		gen P_sentcontrol_labpos=(P_sentcontrol-P_senttreat)/2 + P_senttreat
		gen P_sentnone_labpos=(P_sentnone-P_sentcontrol)/2 + P_sentcontrol
		
		gen x=bin1*0.4
		
		qui sum P_senttreat if bin1==0
		local base_P_sentcontrol_new=`r(N)'
		qui sum P_senttreat if bin1==1
		local base_P_sentcontrol_pre=`r(N)'
		qui sum P_sentcontrol if bin1==0
		local base_P_sentnone_new=`r(N)'
		qui sum P_sentcontrol if bin1==1
		local base_P_sentnone_pre=`r(N)'
			
		twoway 	(bar P_sentnone x if bin1==0, barwidth(0.2) lcolor(red%50) fcolor(red%50) base(`base_P_sentnone_new')) ///
				(bar P_sentnone x if bin1==1, barwidth(0.2) lcolor(red%50) fcolor(red%50) base(`base_P_sentnone_pre')) ///
				(bar P_sentcontrol x if bin1==1, barwidth(0.2) lcolor(emidblue%80) fcolor(emidblue%80) base(`base_P_sentcontrol_pre')) ///
				(bar P_senttreat x if bin1==0, barwidth(0.2) lcolor(dkgreen) fcolor(dkgreen)) ///
				(bar P_senttreat x if bin1==1, barwidth(0.2) lcolor(dkgreen) fcolor(dkgreen)) ///
				(scatter P_senttreat_labpos x, msym(none) mlabel(P_senttreat_lab) mlabpos(0) mlabgap(0) mlabcolor(black) mlabsize(small)) ///
				(scatter P_sentcontrol_labpos x if bin1==1, msym(none) mlabel(P_sentcontrol_lab) mlabpos(0) mlabgap(0) mlabcolor(black) mlabsize(small)) ///
				(scatter P_sentnone_labpos x, msym(none) mlabel(P_sentnone_lab) mlabpos(0) mlabgap(0) mlabcolor(black) mlabsize(small)) ///
				, ///
				graphregion(color(white)) bgcolor(white) ///
				xscale(range(-0.25 0.65)) ///
				yscale(range(0 100)) yticks(0(10)100) ylabel(0(10)100) ///
				xlabel(0 "{it:New}" 0.4 "{it:Pre-existing}", noticks) ///
				legend(order(5 "Treatment arm communication adopted" 3 "Control arm communication adopted" 1 "No communication adopted") cols(1) pos(6)) ///
				xtitle(" " "{bf:Communication in trial existed before the trial?}") ytitle("Percent of trials")
		graph export "figures/adoption_by_any_preexist.pdf", replace
	}
}

******************************************
***FIGURE 9: PRE-EXISTENCE AND EVIDENCE***
******************************************
{ 
	{ // 9a
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1

		mat bar=J(4,8,.) 
		mat colnames bar = bin1 bin2 p_adopt lb ub N N_adopt N_nadopt

		local r=1
		forvalues s=0/1 {
			forvalues t=0/1 {
				qui reg adopted ibn.treatmenteffect_maxt_sig if comm_preexisted==`s', nocons cl(cityid)
				mat bar[`r',1]=`s'
				mat bar[`r',2]=`t'
				mat bar[`r',3]=_b[`t'.treatmenteffect_maxt_sig]
				mat bar[`r',4]=_b[`t'.treatmenteffect_maxt_sig]+invttail(e(df_r),0.975)*_se[`t'.treatmenteffect_maxt_sig]
				mat bar[`r',5]=_b[`t'.treatmenteffect_maxt_sig]+invttail(e(df_r),0.975)*_se[`t'.treatmenteffect_maxt_sig]
				qui count if comm_preexisted==`s' & treatmenteffect_maxt_sig==`t' & adopted !=.
				mat bar[`r',6]=r(N)
				qui count if comm_preexisted==`s' & treatmenteffect_maxt_sig==`t' & adopted ==1
				mat bar[`r',7]=r(N)
				qui count if comm_preexisted==`s' & treatmenteffect_maxt_sig==`t' & adopted ==0
				mat bar[`r',8]=r(N)
				local ++r
			}
		}

		qui reg adopted 1.treatmenteffect_maxt_sig if comm_preexisted==0, cl(cityid)
		local pval0=string(2*ttail(e(df_r),abs(_b[1.treatmenteffect_maxt_sig]/_se[1.treatmenteffect_maxt_sig])),"%3.2f")
		
		qui tab treatmenteffect_maxt_sig adopted if comm_preexisted==1, exact
		local pval1=string(`r(p_exact)',"%3.2f")
		
		qui reg adopted 1.treatmenteffect_maxt_sig##1.comm_preexisted, cl(cityid)
		local pvald=string(2*ttail(e(df_r),abs(_b[1.treatmenteffect_maxt_sig#1.comm_preexisted]/_se[1.treatmenteffect_maxt_sig#1.comm_preexisted])),"%3.2f")

		clear
		svmat bar, names(col)
		
		replace p_adopt=p_adopt*100
		replace ub=ub*100
		replace lb=lb*100
		
		tostring p_adopt, gen(barlabel) format("%2.0f") force
		replace barlabel=barlabel+"%"
		
		tostring N, replace format("%3.0f") force
		tostring N_adopt, replace format("%3.0f") force
		
		replace barlabel=barlabel+" ("+N_adopt+"/"+N+")"
		
		local maxy 100
		
		egen max=max(p_adopt), by(bin1 bin2)
		replace max=max+1
		
		sort bin1 bin2
		gen 	x=_n*0.3+bin1*0.2
		qui sum x
		local mx=`r(max)'+0.15
		
		qui sum max if bin1==0
		local yend0=`r(max)'+5
		qui sum p_adopt if bin1==1
		local yend1=`r(max)'+5
		qui sum p_adopt if bin1==0 & bin2==0
		local ystart00=`r(max)'+2
		qui sum p_adopt if bin1==0 & bin2==1
		local ystart01=`r(max)'+2
		qui sum p_adopt if bin1==1 & bin2==0
		local ystart10=`r(max)'+2
		qui sum p_adopt if bin1==1 & bin2==1
		local ystart11=`r(max)'+2
		qui sum x if bin1==0
		local xstart0=`r(min)'
		local xend0=`r(max)'
		local xcent0=`r(mean)'
		qui sum x if bin1==1
		local xstart1=`r(min)'
		local xend1=`r(max)'
		local xcent1=`r(mean)'
		local Ystart0=`yend0'+4
		local Ystart1=`yend1'+4
		local Yend=max(`yend0',`yend1')+5
		local Xcent=(`xcent0'+`xcent1')/2
		
		gen byte zero=0
			
		twoway 	(bar p_adopt x if bin1==0 & bin2==0, barwidth(0.2) lcolor(orange_red) fcolor(orange_red%30)) ///
				(bar p_adopt x if bin1==0 & bin2==1, barwidth(0.2) lcolor(orange_red) fcolor(orange_red%30)) ///
				(bar p_adopt x if bin1==1 & bin2==0, barwidth(0.2) lcolor(midgreen) fcolor(midgreen%70)) ///
				(bar p_adopt x if bin1==1 & bin2==1, barwidth(0.2) lcolor(midgreen) fcolor(midgreen%70)) ///
				`rcap' ///
				(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
				(pci 	`ystart00' `xstart0' `yend0' `xstart0'  `ystart01' `xend0' `yend0' `xend0'  `yend0' `xstart0' `yend0' `xend0' ///
						`ystart10' `xstart1' `yend1' `xstart1'  `ystart11' `xend1' `yend1' `xend1'  `yend1' `xstart1' `yend1' `xend1' ///
						`Ystart0' `xcent0' `Yend' `xcent0'  `Ystart1' `xcent1' `Yend' `xcent1'  `Yend' `xcent0' `Yend' `xcent1' ///
						, lcolor(gray%50)) ///
				, ///
				text(`Ystart0' `xcent0' "{it:p}=`pval0'", size(small) placement(s)) ///
				text(`Ystart1' `xcent1' "{it:p}=`pval1'*", size(small) placement(s)) /// 
				text(`Yend' `Xcent' "{it:p}=`pvald'", size(small) placement(n)) ///
				graphregion(color(white) margin(0 0 0 10)) bgcolor(white) ///
				xscale(range(0.15 `mx')) yscale(range(0 `maxy')) yticks(0(10)`maxy') ylabel(0(10)`maxy') ///
				xlabel(0.3 "{it:No}" 0.6 "{it:Yes}" 1.1 "{it:No}" 1.4 "{it:Yes}", noticks) ///
				legend(off) /// legend(order(1 "New communication" 3 "Pre-existing communication")) ///
				text(105 `xcent0' "{bf:New communication}", placement(n)) ///
				text(105 `xcent1' "{bf:Pre-existing communication}", placement(n)) ///
				xtitle(" " "{bf:Positive and significant result?}") ytitle("Percent of trials adopted") ///
				note("*Calculated using Fisher's exact test" )
		graph export "figures/adoption_by_sig_preexist.pdf", replace
	}
	{ // 9b
		clear all
		use "data/BITTrialAdoption.dta"
		keep if sample==1
		
		binscatter2 adopted treatmenteffect_max, ///
			by(comm_preexisted) nquantiles(5) ///
			yscale(range(0 1)) yticks(0(0.1)1) ylabel(0 "0" 0.1 "10" 0.2 "20" 0.3 "30" 0.4 "40" 0.5 "50" 0.6 "60" 0.7 "70" 0.8 "80" 0.9 "90" 1 "100") ///
			col(orange_red%30 midgreen%70) msym(circle diamond) ///
			legend(order(1 "New communications" 2 "Pre-existing communications")) ///
			xtitle("Max treatment effect (pp.)") ///
			ytitle("Percent of trials adopted") ///
			graphregion(color(white))
		graph export "figures/adoption_by_tebin5_preexist.pdf", replace
	}
}

***********************
***FIGURE 10: SURVEY***
***********************
{ 
	clear all
	use "data/Survey.dta"
	
	mat survey=J(7,5,.)
	mat colnames survey = factor mean se lb ub
	local row=1
	local desclist `" "Prioritization from key decision-makers" "Timely reminders" "Logistics and tech support" "More staff FTE hours" "Staff receive training from external consultants" "Funding for communication costs" "Stronger evidence" "'
	local values
	foreach var in survey_priority survey_remind survey_techsup survey_stafffte survey_training survey_funding survey_evidence {
		local desc: word `row' of `desclist'
		local values `values' `row' "`desc'"
		qui reg `var' [aweight=weight], cl(id)
		mat survey[`row',1]=`row'
		mat survey[`row',2]=_b[_cons]
		mat survey[`row',3]=_se[_cons]
		mat survey[`row',4]=r(table)[5,1]
		mat survey[`row',5]=r(table)[6,1]
		local ++row
	}
	qui distinct id
	local idN=`r(ndistinct)'
	qui distinct state
	local stateN=`r(ndistinct)'
	
	*pval
	local lablist
	local l=1
	foreach var in priority remind techsup stafffte training funding evidence { // same order/numbering as in matrix
		rename survey_`var' survey`l'
		local lablist `lablist' `l' "`l'-`var'"
		local ++l
	}
	
	reshape long survey, i(id trialnumber) j(factor)
	label define factor `lablist'
	label values factor factor
	
	* priority vs logistics and tech
	local priority_ystart=survey[1,"ub"]+0.05
	local techsup_ystart=survey[3,"ub"]+0.05
	local prioritytechsup_yfin=max(`priority_ystart',`techsup_ystart')+0.2
	qui reg survey 1.factor if inlist(factor,1,3) [aweight=weight], cl(id)
	local pval_priority_techsup=string(r(table)[4,1],"%3.2f")
	
	clear
	svmat survey, names(col)
	label define values `values'
	label values factor values 
	decode factor, gen(factor_name)

	tostring mean, gen(barlabel) format("%3.2f") force

	gsort -mean
	gen 	x=_n*0.75
	qui sum x
	local center=`r(mean)'
	local xlabel
	forvalues f=1/7 {
		local fact=factor_name[`f']
		local wc: word count `fact'
		if `wc'==2 {
			local lab1=word("`fact'",1)
			local lab2=word("`fact'",2)
			local lab3=""
		}
		if `wc'==4 {
			local lab1=word("`fact'",1)+" "+word("`fact'",2)
			local lab2=word("`fact'",3)+" "+word("`fact'",4)
			local lab3=""
		}
		if `wc'==6 {
			local lab1=word("`fact'",1)+" "+word("`fact'",2)
			local lab2=word("`fact'",3)+" "+word("`fact'",4)
			local lab3=word("`fact'",5)+" "+word("`fact'",6)
		}
		
		local pos=`f'*0.75
		local xlabel `xlabel' `pos' `" "`lab1'" "`lab2'" "`lab3'" "'
	}

	gen one=1

	twoway 	(bar mean x, barwidth(0.5) lcolor(cranberry) fcolor(cranberry%70) base(1)) ///
			(scatter one x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
			(rcap lb ub x, msize(10) lcolor(gray%50)) ///
			(pci 	`priority_ystart' 0.75 `prioritytechsup_yfin' 0.75 ///
					`techsup_ystart' 1.50 `prioritytechsup_yfin' 1.50 ///
					`prioritytechsup_yfin' 0.75 `prioritytechsup_yfin' 1.50 ///
					, lcolor(gray%50)) ///
			, ///
			graphregion(color(white) margin(0 0 0 10)) ///
			xlabel(`xlabel', noticks labsize(small)) ///
			ylabel(1 "1 - Not at all" 2 "2 - Slightly" 3 "3 - Moderately" 4 "4 - Very" 5 "5 - Extremely", labsize(small) angle(0)) ///
			xsize(10) ysize(5) ///
			xtitle("") ytitle("") ///
			legend(off) ///
			text(`prioritytechsup_yfin' 1.125 "{it:p}=`pval_priority_techsup'", size(small) placement(n)) ///
			text(5.15 `center' "{bf:How helpful would each of the following be for supporting your city to send the communication routinely?}", placement(n)) ///
			note(" " "Responses from `idN' city employees across `stateN' states")
	graph export "figures/survey.pdf", replace
}

********************************
***FIGURE 11: COUNTERFACTUALS***
********************************
{
	clear all
	use "data/BITTrialAdoption.dta"
	keep if sample==1
	append using "data/Forecasts.dta"
	replace cityid=_n+1000 if missing(cityid)

	local b1 0.19
	local b2 1.7
	gen 	tebin=3 if treatmenteffect_max<=`b1' & treatmenteffect_max!=. & treatmenteffect_max!=.
	replace	tebin=2 if treatmenteffect_max>`b1' & treatmenteffect_max<=`b2' & treatmenteffect_max!=. & treatmenteffect_max!=.
	replace	tebin=1 if treatmenteffect_max>`b2' & treatmenteffect_max!=. & treatmenteffect_max!=.

	forvalues b=1/3 {
		qui sum adopt_byte_`b'
		local tebin`b'=`r(mean)'
	}
	gen tebinweight=((tebin==1)*`tebin1' + (tebin==2)*`tebin2' + (tebin==3)*`tebin3')/100

	gen counterfactual1 = treatmenteffect_max if treatmenteffect_max!=.
	gen counterfactual2 = treatmenteffect_max*(adopted==1) if treatmenteffect_max!=.
	gen counterfactual3 = treatmenteffect_max*(treatmenteffect_max>0) if treatmenteffect_max!=.
	gen counterfactual4 = treatmenteffect_max*tebinweight if treatmenteffect_max!=.
	gen diff = counterfactual2 - counterfactual3

	mat bar=J(9,6,.)
	mat colnames bar = group cf mean lb ub n 

	local condlist `" "treatmenteffect_max==treatmenteffect_max" "comm_preexisted==0" "comm_preexisted==1" "'
	local g=1
	local r=1
	foreach cond in `condlist' {
		forvalues c=2/4 {
			mat bar[`r',1]=`g'
			mat bar[`r',2]=`c'
			
			qui reg counterfactual`c' if `cond', cl(cityid)
			mat bar[`r',3]=_b[_cons]
			mat bar[`r',4]=_b[_cons]+invttail(e(df_r),0.975)*_se[_cons]
			mat bar[`r',5]=_b[_cons]+invttail(e(df_r),0.025)*_se[_cons]
			mat bar[`r',6]=`e(N)'
			
			local ++r
		}
		qui reg counterfactual1 if `cond', cl(cityid)
		local avg`g'=string(_b[_cons],"%3.2f")
		local N`g'=`e(N)'
		
		preserve
			expand 2, gen(exp)
			qui reg counterfactual2 if `cond' & exp==0
			est sto x
			qui reg counterfactual3 if `cond' & exp==1
			est sto y
			suest x y, r
			lincom [x_mean]_cons-[y_mean]_cons
			local pval`g'=string(`r(p)',"%3.2f") // assuming two independent "counterfactual" samples
		restore
		preserve
			expand 2, gen(exp)
			qui reg counterfactual2 if `cond' & exp==0
			est sto x
			qui reg counterfactual4 if `cond' & exp==1
			est sto y
			suest x y, r
			lincom [x_mean]_cons-[y_mean]_cons
			local pval2`g'=string(`r(p)',"%3.2f") // assuming two independent "counterfactual" samples
		restore
		local ++g
	}

	svmat bar, names(col)
	drop if group==.
	drop if cf==4 & group!=1

	tostring mean, gen(barlabel) format("%3.2f") force
	replace barlabel=barlabel+" pp."

	gen x=_n*0.3 + (group-1)*0.15
	qui sum x
	local mx = `r(max)'+0.15
	gen byte zero=0

	forvalues g=1/3 {
		qui sum ub if group==`g' & cf==2
		local y1`g'=`r(max)'+0.25
		qui sum ub if group==`g' & cf==3
		local y2`g'=`r(max)'+0.25
		local yend`g'=max(`y1`g'',`y2`g'')+0.1
		qui sum x if group==`g' & cf==2
		local x1`g'=`r(mean)'
		qui sum x if group==`g' & cf==3
		local x2`g'=`r(mean)'
		local xcent`g'=(`x1`g''+`x2`g'')/2
	}

	qui sum ub if group==1 & cf==2
	local y11=`r(max)'+0.25
	qui sum ub if group==1 & cf==4
	local y31=`r(max)'+0.25
	local yend11=max(`y11',`y21')+0.1
	qui sum x if group==1 & cf==2
	local x11=`r(mean)'
	qui sum x if group==1 & cf==4
	local x31=`r(mean)'
	local xcent11=(`x11'+`x31')/2

	local y11=max(`y11',`y12',`y13')
	local y12=max(`y11',`y12',`y13')
	local y13=max(`y11',`y12',`y13')
	local y21=max(`y21',`y22',`y23')
	local y22=max(`y21',`y22',`y23')
	local y23=max(`y21',`y22',`y23')
	local y11=max(`y11',`y21')
	local y12=max(`y12',`y22')
	local y13=max(`y13',`y23')
	local yend1=max(`yend1',`yend2',`yend3')
	local yend2=max(`yend1',`yend2',`yend3')
	local yend3=max(`yend1',`yend2',`yend3')
	local yend11=`yend1'
	local yend1=`yend1'-0.5
	local y31=`y11'
	local y11=`y11'-0.5
	local y21=`y21'-0.5

	twoway 		(pci 	`avg1' 0.15 `avg1' 1.125 ///
						`avg2' 1.125 `avg2' 1.875 ///
						`avg3' 1.875 `avg3' `mx', ///
						lcolor(lime%80)) ///
				(bar mean x if group==1 & cf==2, barwidth(0.2) lcolor(ebblue) fcolor(ebblue%20)) ///
				(bar mean x if group==1 & cf==3, barwidth(0.2) lcolor(emerald) fcolor(emerald%80)) ///
				(bar mean x if group==1 & cf==4, barwidth(0.2) lcolor(gray) fcolor(gray%50)) ///
				(bar mean x if group==2 & cf==2, barwidth(0.2) lcolor(ebblue) fcolor(ebblue%30)) ///
				(bar mean x if group==2 & cf==3, barwidth(0.2) lcolor(emerald) fcolor(emerald%80)) ///
				(bar mean x if group==3 & cf==2, barwidth(0.2) lcolor(ebblue) fcolor(ebblue%30)) ///
				(bar mean x if group==3 & cf==3, barwidth(0.2) lcolor(emerald) fcolor(emerald%80)) ///
				(rcap lb ub x, msize(10) lcolor(gray%50)) ///
				(scatter zero x, msym(none) mlabel(barlabel) mlabpos(12) mlabcolor(black) mlabsize(small)) ///
				(pci 	`y31' `x11' `yend11' `x11'  `y31' `x31' `yend11' `x31'  `yend11' `x11' `yend11' `x31' ///
						`y11' `x11' `yend1' `x11'  `y21' `x21' `yend1' `x21'  `yend1' `x11' `yend1' `x21' ///
						`y11' `x11' `yend1' `x11'  `y21' `x21' `yend1' `x21'  `yend1' `x11' `yend1' `x21' ///
						`y12' `x12' `yend2' `x12'  `y22' `x22' `yend2' `x22'  `yend2' `x12' `yend2' `x22' ///
						`y13' `x13' `yend3' `x13'  `y23' `x23' `yend3' `x23'  `yend3' `x13' `yend3' `x23' ///
						, lcolor(gray%50)) ///
				, ///
				graphregion(color(white)) bgcolor(white) ///
				xline(1.125, lpattern(dash) lcolor(gray%50)) ///
				xline(1.875, lpattern(dash) lcolor(gray%50)) ///
				xscale(range(0.15 `mx')) yscale(range(0 6)) yticks(0(1)6) ylabel(0(1)6) ///
				xlabel(0.6 "All trials ({it:N}=`N1')" 1.5 `" "Trials with new" "communications ({it:N}=`N2')" "' 2.25 `" "Trials with pre-existing" "communications ({it:N}=`N3')" "', noticks) ///
				legend(order(2 "Observed adoptions" 3 "Counterfactual adoption of trials with positive effects" 4 "Forecasted adoption from predictions by effect size bins" 1 "Average treatment effect of most effective nudge arms") cols(1)) ///
				xtitle(" ") ytitle("Average treatment effect (pp.)") ///
				text(`yend1' `xcent1' "{it:p}=`pval1'", size(small) placement(n)) ///
				text(`yend2' `xcent2' "{it:p}=`pval2'", size(small) placement(n)) ///
				text(`yend3' `xcent3' "{it:p}=`pval3'", size(small) placement(n)) ///
				text(`yend11' `xcent11' "{it:p}=`pval21'", size(small) placement(n)) ///
				xsize(16) ysize(9)
	graph export "figures/counterfactuals.pdf", replace
}

************************************
***FIGURE 12: HJORT ET AL. (2021)***
************************************
{ 
	clear all
	import delimited "data/policyadoption_raw.csv"

	* Generate additional adoption categories
	egen implemented1_sum=rowtotal(implemented1_ontime implemented1_audits implemented1_social implemented1_before implemented1_letter) if implemented1!=.
	gen byte implemented1_allmech=(implemented1_ontime + implemented1_audits + implemented1_social == 3) if implemented1_sum!=.
	label var implemented1_allmech "Adopted all 3 mechanisms (ontime, audits, social)"

	bysort munic_id: gen n=_n
	* Take MAX of adoption measures (since both mayor and city staff included; sometimes non-agreement, so take max)
	egen implemented1_allmech_max=max(implemented1_allmech), by(munic_id)
	replace implemented1_allmech_max=. if n!=1 // only one obs per city

	local nudge implemented1_allmech
	*Control group moments
	qui tab `nudge' implemented1_letter if treatment_assignment==0, matcell(Pc)
	local Nc_nn=Pc[1,1]
	local Nc_ln=Pc[1,2]
	local Nc_nd=Pc[2,1]
	local Nc_ld=Pc[2,2]
	mat Pc=Pc/`r(N)'
	local Pc_nn=Pc[1,1]
	local Pc_ln=Pc[1,2]
	local Pc_nd=Pc[2,1]
	local Pc_ld=Pc[2,2]

	*Treatment group moments
	qui tab `nudge' implemented1_letter if treatment_assignment==1, matcell(Pt) 
	local Nt_nn=Pt[1,1]
	local Nt_ln=Pt[1,2]
	local Nt_nd=Pt[2,1]
	local Nt_ld=Pt[2,2]
	mat Pt=Pt/`r(N)'
	local Pt_nn=Pt[1,1]
	local Pt_ln=Pt[1,2]
	local Pt_nd=Pt[2,1]
	local Pt_ld=Pt[2,2]	

	foreach g in Pc Pt {
		foreach c in nn ln nd ld {
			local `g'_`c's=string(100*``g'_`c'',"%3.2f")
		}
	}

	file open hjort_fig using "figures/hjort_fig.txt", write replace text

	file write hjort_fig ///
		"\begin{center}" _n ///
		"\begin{tikzpicture}[thick, node distance=0.75in, every text node part/.style={align=center}]" ///
		_n ///
		"% No Letter + No Nudge" _n ///
		"\node[draw," _n ///
			"rectangle," _n ///
			"minimum width=2.15in," _n ///
			"minimum height=0.75in] (nn) {\textbf{No Letter + No Nudge} \\ \vspace{-0.5em} \\ Control \% ($ N)=`Pc_nns'\% \: (`Nc_nn')$ \\ Treatment \% ($ N)=`Pt_nns'\% \: (`Nt_nn')$};" _n ///
		_n ///
		"% No Letter + Nudge" _n ///
		"\node[draw," _n ///
			"rectangle," _n ///
			"minimum width=2.15in," _n ///
			"minimum height=0.75in," _n ///
			"below=of nn" _n ///
			"] (nd) {\textbf{No Letter + Nudge} \\ \vspace{-0.5em} \\ Control \% ($ N)=`Pc_nds'\% \: (`Nc_nd')$ \\ Treatment \% ($ N)=`Pt_nds'\% \: (`Nt_nd')$};" _n ///
		_n ///
		"% Letter + No Nudge" _n ///
		"\node[draw," _n ///
			"rectangle," _n ///
			"minimum width=2.15in," _n ///
			"minimum height=0.75in," _n ///
			"right=of nn" _n ///
			"] (ln) {\textbf{Letter + No Nudge} \\ \vspace{-0.5em} \\ Control \% ($ N)=`Pc_lns'\% \: (`Nc_ln')$ \\ Treatment \% ($ N)=`Pt_lns'\% \: (`Nt_ln')$};" _n ///
		_n ///
		"% Letter + Nudge" _n ///
		"\node[draw," _n ///
			"rectangle," _n ///
			"minimum width=2.15in," _n ///
			"minimum height=0.75in," _n ///
			"below=of ln" _n ///
			"] (ld) {\textbf{Letter + Nudge} \\ \vspace{-0.5em} \\ Control \% ($ N)=`Pc_lds'\% \: (`Nc_ld')$ \\ Treatment \% ($ N)=`Pt_lds'\% \: (`Nt_ld')$};" _n ///
		_n ///
		"% Arrows" _n ///
		"\draw[-latex] (nn) --node[pos=0.5,above]{$ f$} (ln);" _n ///
		"\draw[-latex] (nn.south east) --node[pos=0.5,above right]{$ f\text{ (diagonal)}$} (ld.north west);" _n ///
		"\draw[-latex] (nn) --node[pos=0.5,right]{$ f$} (nd);" _n ///
		"\draw[-latex] (nd) --node[pos=0.5,above]{$ f$} (ld);" _n ///
		"\draw[-latex] (ln) --node[pos=0.5,right]{$ f\text{ (pre-existing)}$} (ld);" _n ///
		_n ///
		"\end{tikzpicture}" _n ///
		"\end{center}"
		
	file close hjort_fig	
}